package com.skeyedu.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description 描述
 * @Author 羽落陌殇
 * @Date 2021/7/15 17:26
 * @Version 1.0.0
 */
public class CharacterEncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        // 处理中文乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTf-8");
        // 拦截放行
        chain.doFilter(request, response);
    }
}
